var dtCh= "/";
var minYear=1900;
var maxYear=2100;
var reWhitespace = /^\s+$/;
/**
 * Check input number string
 * @param s: string need to be checked
 * @return:
 * true: if s only contain number
 * false: otherwise
 */
function isNatural(s){
	var i;
	if (s == null || $.trim(s).length == 0) {
		return false;
	}	
	for (i = 0; i < s.length; i++){   
		// Check that current character is number.
		var c = s.charAt(i);
		if (((c < "0") || (c > "9"))) return false;
	}
	// All characters are numbers.
	return true;
}
/**
* Check input is integer number
* @param s string need to be checked
* @return
* true: if input is integer
* false: otherwise
*/
function isInteger(s){
	var i=0;
	if (s == null || $.trim(s).length == 0) {
		return false;
	}
	var c=	s.charAt(i);
	if (((c < "0") || (c > "9")) && (c!='-') && (c!='+')){
		return false;
	}
	for (i = 1; i < s.length; i++){   
		// Check that current character is number.
		c = s.charAt(i);
		if (((c < "0") || (c > "9"))){
			return false;
		}
	}
	// All characters are numbers.
	return true;
}
/**
* Check float number
* TODO: not localize yet
* @param s
* @return
*/
function isFloating(s){
	if(s=="." || s == ","){
		return false;
	}
	s = s.replace(",",".");	
	parts	=	s.split(".");
	if(parts.length > 2){
		return false;
	}
	var i;
	for(i=0; i < parts.length; i++){
		if(!isNatural(parts[i])){
			return false;
		}
	}
	return true;
}
/**
* Return number of days in February
* @param year
* @return
* 29: leap year
* 28: not a leap year
*/
function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
	// EXCEPT for centurial years which are not also divisible by 400.
	return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
	} 
	return this
}

function fixedDateCheck(dtStr) {
	var daysInMonth = DaysArray(12)

	var full = /^\d{1,2}\/\d{1,2}\/\d{4}$/;	

	var strDay = '1';
	var strMonth = '1';
	var strYear = '';
	if (full.test(dtStr)) {
		var dArr = dtStr.split("/");
		strDay = dArr[0];
		strMonth = dArr[1];
		strYear = dArr[2]; 
	} else { 		
		return _("Invalid date");
	}

	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1);
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1);
	for (var i = 1; i <= 3; i++) {
		if (strYear.charAt(0)=="0" && strYear.length>1) strYear=strYear.substring(1);
	}

	var day		= parseInt(strDay, 10);	
	var month	= parseInt(strMonth, 10);	
	var year	= parseInt(strYear, 10);

	if (strDay != '' && (day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month])){
		return _("Invalid date");		
	}

	if (strMonth != '' && (month<1 || month>12)){
		return _("Invalid month");		
	}

	if (strYear != '' && (year==0 || year<minYear || year>maxYear)){
		return _("Invalid year. Year must be between {0} and {1}",minYear,maxYear);		
	}
	return true;
}


/**
* Check inputed date is valid or not * 
* @param strYear : inputed year
* @param strMonth : inputed month
* @param strDay: inputed day
* @param checkWithCurDate
* true: check inputed date is greater than current date.
* @return
* Invalid day: day must be a number, day must be in range(according to month)
* Invalid month: month must be a number, and range[1..12]
* Invalid year. Year must be between {0} and {1}: year must be a number, and in range [1900..2100]
* Inputed date is greater then current date: if checkWithCurDate is set to true
* and the inputed date is greater than current date.
* true: if passed listed condition.
*  
*/
function isDate(strYear, strMonth, strDay, checkWithCurDate){
	var daysInMonth = 	DaysArray(12);
	var dayFormat 	= 	/^\d{0,2}$/;
	var yearFormat 	= 	/^\d{4}$/;

	var day		= parseInt(strDay, 10);
	var month	= parseInt(strMonth, 10);	
	var year	= parseInt(strYear, 10);
	// Check day.
    if (!dayFormat.test(strDay) || (strDay != '' && (day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]))){
        var res =   new Array();
        res['errId']    =   'd';
        res['errMsg']   =   _("Invalid day");
        return res;     
    }
    
    // Check month. Invalid case if month < 1 or month >12 or (month=empty while day !=empty)
    if (!dayFormat.test(strMonth) || (strMonth != '' && (month<1 || month>12))
            || (strMonth.length==0 && strDay.length > 0)){
        var res =   new Array();
        res['errId']    =   'm';
        res['errMsg']   =   _("Invalid month");
        return res;     
    }
    
	// Year must be a 4-digit number between 1900 and 2100
    if (!yearFormat.test(strYear) || (strYear != '' && (year==0 || year<minYear || year>maxYear))){
        var res =   new Array();
        res['errId']    =   'y';
        res['errMsg']   =   _("Invalid year. Year must be between {0} and {1}",minYear,maxYear);
        return res;     
    }
    
	if (checkWithCurDate == true) {
		var myDate=new Date();
		myDate.setFullYear(year, month - 1, day);
		var today = new Date();
		if (myDate>today) {
			var res	=	new Array();
			res['errId']	=	'date';
			res['errMsg']	=	_("Inputted date is greater then current date");
			return res;
		}
	}	
	return true;
}

function isDateEx(strYear, strMonth, strDay, checkWithCurDate, condition){
	var daysInMonth = 	DaysArray(12);
	var dayFormat 	= 	/^\d{0,2}$/;
	var yearFormat 	= 	/^\d{4}$/;

	var day		= parseInt(strDay, 10);
	var month	= parseInt(strMonth, 10);	
	var year	= parseInt(strYear, 10);
	// Check day.
    if (!dayFormat.test(strDay) || (strDay != '' && (day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]))){
        var res =   new Array();
        res['errId']    =   'd';
        res['errMsg']   =   _("Invalid day");
        return res;     
    }
    
    // Check month. Invalid case if month < 1 or month >12 or (month=empty while day !=empty)
    if (!dayFormat.test(strMonth) || (strMonth != '' && (month<1 || month>12))
            || (strMonth.length==0 && strDay.length > 0)){
        var res =   new Array();
        res['errId']    =   'm';
        res['errMsg']   =   _("Invalid month");
        return res;     
    }
    
	// Year must be a 4-digit number between 1900 and 2100
    if (!yearFormat.test(strYear) || (strYear != '' && (year==0 || year<minYear || year>maxYear))){
        var res =   new Array();
        res['errId']    =   'y';
        res['errMsg']   =   _("Invalid year. Year must be between {0} and {1}",minYear,maxYear);
        return res;     
    }
    
    if (checkWithCurDate == true) {
		var myDate=new Date();
		myDate.setFullYear(year, month - 1, day);
		var today = new Date();
		switch (condition) {
		case 'gt':		
			if (myDate<=today) {			
				var res	=	new Array();
				res['errId']	=	'date';
				res['errMsg']	=	_("Inputted date is less then current date");
				return res;
			}
			break;
		default:
			break;
		}
    }
	
	
		
	return true;
}

/**
* Check the validity of given date. The error message will be filled to [target]
* if the given date is not valid. 
* @param objYear: jquery object of year ex: $("#yyyy")
* @param objMonth: jquery object of month
* @param objDay: jquery object of day
* @param checkEmpty
* true: always check given date.
* false: only check given date if it's not empty
* @param message: error message.
* @param target: id of <span> for display error message
* @param checkWithCurDate
* @return
* true: given date is valid
* false: given date is invalid
*/
function checkDateEx(objYear, objMonth, objDay, checkEmpty, message, target, checkWithCurDate, condition){
	if(checkEmpty){
		if(!isNotEmpty(objYear, '', target)){
			objYear.css("border-color", "red");
			if (message == null || $.trim(message) == '') {
				message = _("Empty year");
			}
			$('span#' + target).text(message).show();
			return false;
		}
		else{
			objYear.css("border-color", "#AAA");
		}
	} else {

		if((objYear == null || $.trim(objYear.val()) == '')
				&& (objMonth == null || $.trim(objMonth.val()) == '')
				&& (objDay == null || $.trim(objDay.val()) == '')) {
			if (objYear != null) {
				objYear.css("border-color", "#AAA");
			}
			if (objMonth != null) {
				objMonth.css("border-color", "#AAA");
			}
			if (objDay != null) {
				objDay.css("border-color", "#AAA");
			}

			return true;
		}

	}
	var res 	= 	isDateEx($.trim(objYear.val()),$.trim(objMonth.val()),$.trim(objDay.val()),checkWithCurDate, condition);
	if(res != true) {
		switch(res['errId']){
		case 'd':
			objDay.css("border-color", "red");
			objMonth.css("border-color", "#AAA");
			objYear.css("border-color", "#AAA");
			break;
		case 'm':
			objDay.css("border-color", "#AAA");
			objMonth.css("border-color", "red");
			objYear.css("border-color", "#AAA");
			break;
		case 'y':
			objYear.css("border-color", "red");
			objDay.css("border-color", "#AAA");
			objMonth.css("border-color", "#AAA");
			break;
		default:
			objDay.css("border-color", "red");
		objMonth.css("border-color", "red");
		objYear.css("border-color", "red");
		break;
		}
		$('span#' + target).text(res['errMsg']).show();
		return false;
	} 
	objDay.css("border-color", "#AAA");
	objMonth.css("border-color", "#AAA");
	objYear.css("border-color", "#AAA");
	$('span#' + target).text('');
	return true;
}

// @author: PPDong, 2009-06-08
function isFullDate(strYear, strMonth, strDay, checkWithCurDate){
	var daysInMonth = 	DaysArray(12);
	var dayFormat 	= 	/^\d{1,2}$/;
	var yearFormat 	= 	/^\d{4}$/;

	var day		= parseInt(strDay, 10);
	var month	= parseInt(strMonth, 10);
	var year	= parseInt(strYear, 10);

	if (!dayFormat.test(strDay) || ((day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]))){
		var res	=	new Array();
		res['errId']	=	'd';
		res['errMsg']	=	_("Invalid date");
		return res;		
	}

	if (!dayFormat.test(strMonth) || (month<1 || month>12)){
		var res	=	new Array();
		res['errId']	=	'm';
		res['errMsg']	=	_("Invalid month");
		return res;		
	}

	if (!yearFormat.test(strYear) || ((year==0 || year<minYear || year>maxYear))){
		var res	=	new Array();
		res['errId']	=	'y';
		res['errMsg']	=	_("Invalid year. Year must be between {0} and {1}",minYear,maxYear);
		return res;		
	}

	if (checkWithCurDate == true) {
		var myDate=new Date();
		myDate.setFullYear(year, month - 1, day);
		var today = new Date();
		if (myDate>today) {
			var res	=	new Array();
			res['errId']	=	'date';
			res['errMsg']	=	_("Inputted date is greater then current date");
			return res;
		}
	}	
	return true;
}

function getAge(birthday_id,age_id){	
	now = new Date();
	if($('#' + birthday_id).val().length <= 0) {
		$('#' + age_id).val('');
		return;
	}
	bD = $('#' + birthday_id).val().split(dtCh);
	var arrDate=new Array(3);
	arrDate[0]="1";//day
	arrDate[1]="1";//month
	arrDate[2]="0";// year
	var j=2;
	for(var i=bD.length-1;i>=0;i--){
		arrDate[j]=bD[i];
		j--;
	}
	born = new Date(arrDate[2], arrDate[1]*1-1, arrDate[0]);
	years = new Date(now.getTime() - born.getTime());
	base = new Date(0);
	$('#' + age_id).val(years.getFullYear()-base.getFullYear());
}

function getBirthday(age_id, birthday_id){
	var txt_age=document.getElementById(age_id);	
	now = new Date();
	var curYear=now.getUTCFullYear();
	var txt_birthday=document.getElementById(birthday_id);
	txt_birthday.value = curYear-txt_age.value;
}

function isNotEmpty(obj, message, target) {
	if ($.trim(obj.val()).length == 0) {
		obj.css("border-color", "red");
		$('span#' + target).text(message).show();
		return false;
	} else {
		obj.css("border-color", "#AAA");
		$('span#' + target).text('');;
		return true;
	}
}

function simpleDateCheck(obj, message, target) {
	if (isNotEmpty(obj, message, target)) {
		var res = fixedDateCheck(obj.val());
		if(res != true) {
			obj.css("border-color", "red");
			$('span#' + target).text(res).show();
			return false;
		} 
		return true;
	}
	return false;
}

/**
* Check the validity of given date. The error message will be filled to [target]
* if the given date is not valid. 
* @param objYear: jquery object of year ex: $("#yyyy")
* @param objMonth: jquery object of month
* @param objDay: jquery object of day
* @param checkEmpty
* true: always check given date.
* false: only check given date if it's not empty
* @param message: error message.
* @param target: id of <span> for display error message
* @param checkWithCurDate
* @return
* true: given date is valid
* false: given date is invalid
*/
function checkDate(objYear, objMonth, objDay, checkEmpty, message, target, checkWithCurDate){
	if(checkEmpty){
		if(!isNotEmpty(objYear, '', target)){
			objYear.css("border-color", "red");
			if (message == null || $.trim(message) == '') {
				message = _("Empty year");
			}
			$('span#' + target).text(message).show();
			return false;
		}
		else{
			objYear.css("border-color", "#AAA");
		}
	} else {

		if((objYear == null || $.trim(objYear.val()) == '')
				&& (objMonth == null || $.trim(objMonth.val()) == '')
				&& (objDay == null || $.trim(objDay.val()) == '')) {
			if (objYear != null) {
				objYear.css("border-color", "#AAA");
			}
			if (objMonth != null) {
				objMonth.css("border-color", "#AAA");
			}
			if (objDay != null) {
				objDay.css("border-color", "#AAA");
			}

			return true;
		}

	}
	var res 	= 	isDate($.trim(objYear.val()),$.trim(objMonth.val()),$.trim(objDay.val()),checkWithCurDate);
	if(res != true) {
		switch(res['errId']){
		case 'd':
			objDay.css("border-color", "red");
			objMonth.css("border-color", "#AAA");
			objYear.css("border-color", "#AAA");
			break;
		case 'm':
			objDay.css("border-color", "#AAA");
			objMonth.css("border-color", "red");
			objYear.css("border-color", "#AAA");
			break;
		case 'y':
			objYear.css("border-color", "red");
			objDay.css("border-color", "#AAA");
			objMonth.css("border-color", "#AAA");
			break;
		default:
			objDay.css("border-color", "red");
		objMonth.css("border-color", "red");
		objYear.css("border-color", "red");
		break;
		}
		$('span#' + target).text(res['errMsg']).show();
		return false;
	} 
	objDay.css("border-color", "#AAA");
	objMonth.css("border-color", "#AAA");
	objYear.css("border-color", "#AAA");
	$('span#' + target).text('');
	return true;
}
/**
* check validity of given day
* @param obj: jquery object of day
* @param checkEmpty
* true: always check given day.
* false: only check given day if it's not empty
* @param message: error message.
* @param target: id of <span> for display error message
* @return
* true: given day is valid
* false: given day is invalid
*
**/
function checkDay(obj, checkEmpty, message, target){
	if(checkEmpty){
		if(!isNotEmpty(obj, message, target)){
			obj.css("border-color", "red");
			if (message == null || $.trim(message) == '') {
				message = _("Empty day");
			}
			$('span#' + target).text(message).show();
			return false;
		}
		else{
			obj.css("border-color", "#AAA");
		}
	}
	var dayFormat	=	/^\d{0,2}$/;
	var	day			=	parseInt($.trim(obj.val()), 10);
	if(!dayFormat.test($.trim(obj.val()))||(day<1) || (day > 31)){
		$('span#' + target).text(_("Invalid day")).show();
		obj.css("border-color", "red");
		return false;
	}
	obj.css("border-color", "#AAA");
	$('span#' + target).text('');
	return true;
}
/**
* check validity of given month
* @param obj: jquery object of month
* @param checkEmpty
* true: always check given month.
* false: only check given month if it's not empty
* @param message: error message.
* @param target: id of <span> for display error message
* @return
* true: given month is valid
* false: given month is invalid
*
**/
function checkMonth(obj, checkEmpty, message, target){
	if(checkEmpty){
		if(!isNotEmpty(obj, message, target)){
			obj.css("border-color", "red");
			if (message == null || $.trim(message) == '') {
				message = _("Empty month");
			}
			$('span#' + target).text(message).show();
			return false;
		}
		else{
			obj.css("border-color", "#AAA");
		}
	}
	var dayFormat	=	/^\d{0,2}$/;
	var	day			=	parseInt($.trim(obj.val()), 10);
	if(!dayFormat.test($.trim(obj.val()))||(day<1) || (day > 12)){
		$('span#' + target).text(_("Invalid month")).show();
		obj.css("border-color", "red");
		return false;
	}
	obj.css("border-color", "#AAA");
	$('span#' + target).text('');
	return true;
}

function checkFullDate(objYear, objMonth, objDay, checkEmpty, message, target, checkWithCurDate){
	if(checkEmpty){
		if(!isNotEmpty(objYear, '', target) && !isNotEmpty(objMonth, '', target) && !isNotEmpty(objDay, '', target)){
			objYear.css("border-color", "red");
			objMonth.css("border-color", "red");
			objDay.css("border-color", "red");
			$('span#' + target).text(message).show();
			return false;
		}
		else{
			objYear.css("border-color", "#AAA");
			objMonth.css("border-color", "#AAA");
			objDay.css("border-color", "#AAA");
		}
	}
	var res 	= 	isFullDate($.trim(objYear.val()),$.trim(objMonth.val()),$.trim(objDay.val()),checkWithCurDate);
	if(res != true) {
		switch(res['errId']){
		case 'd':
			objDay.css("border-color", "red");
			objMonth.css("border-color", "#AAA");
			objYear.css("border-color", "#AAA");
			break;
		case 'm':
			objDay.css("border-color", "#AAA");
			objMonth.css("border-color", "red");
			objYear.css("border-color", "#AAA");
			break;
		case 'y':
			objYear.css("border-color", "red");
			objDay.css("border-color", "#AAA");
			objMonth.css("border-color", "#AAA");
			break;
		default:
			objDay.css("border-color", "red");
		objMonth.css("border-color", "red");
		objYear.css("border-color", "red");
		break;
		}
		$('span#' + target).text(res['errMsg']).show();
		return false;
	} 
	objDay.css("border-color", "#AAA");
	objMonth.css("border-color", "#AAA");
	objYear.css("border-color", "#AAA");
	$('span#' + target).text('');
	return true;

}
function checkNumber(obj, message, target, formBorderColor) {
	if ($.trim(obj.val()).length > 0 && !isNatural(obj.val())) {
		obj.css("border-color", "red");
		$('span#' + target).text(message).show();
		return false
	}
	obj.css("border-color", formBorderColor);
	$('span#' + target).text('').hide();
	return true;
}

function checkNumberInRange(obj, min, max, message, target,  formBorderColor){
	var val	=	$.trim(obj.val());
	if (val.length) {
		if((!isInteger(val)) || (val < min) || (val > max)){
			obj.css("border-color", "red");
			$('span#' + target).text(message).show();
			return false;
		}
	}
	obj.css("border-color", formBorderColor);
	$('span#' + target).text('').hide();
	return true;
}

function checkFloatingNumberInRange(obj, min, max, message, target,  formBorderColor){
	var val	=	$.trim(obj.val());
	if (val.length) {
		if((!isFloating(val)) || (val < min) || (val > max)){
			obj.css("border-color", "red");
			$('span#' + target).text(message).show();
			return false;
		}
	}
	obj.css("border-color", formBorderColor);
	$('span#' + target).text('').hide();
	return true;
}

function checkFloatingNumber(obj, message, target, formBorderColor) {
	if ($.trim(obj.val()).length > 0 && !isFloating(obj.val())) {
		obj.css("border-color", "red");
		$('span#' + target).text(message).show();
		return false;
	}
	obj.css("border-color", formBorderColor);
	$('span#' + target).text('').hide();
	return true;
}
function checkEmail(obj, message, target, formBorderColor) {
	var reEmail = /^.+\@.+\..+$/;
	if ($.trim(obj.val()).length > 0) {
		res = reEmail.test(obj.val());
		if (res == false) {
			obj.css("border-color", "red");
			$('span#' + target).text(message).show();
			return false;
		}
	}
	obj.css("border-color", formBorderColor);
	$('span#' + target).text('').hide();
	return true;
}
/**
* Compare 2 date with format the same format
* dd/mm/yyyy
* mm/yyyy
* yyyy
* @param dtStr1
* @param dtStr2
* @return
* 'gt' : dtStr1 > dtStr2
* 'lt' : dtStr1 < dtStr2
* 'eq' : dtStr1 = dtStr2
* dtStr2='today'
* 'gtToday' : dtStr1 > current day
* 'ltToday' : dtStr1 < current day
* 'eqToday' : dtStr1 = current day
*/
function compareDate(dtStr1, dtStr2){
	var daysInMonth = DaysArray(12)

	var full = /^\d{1,2}\/\d{1,2}\/\d{4}$/;
	var medium = /^\d{1,2}\/\d{4}$/;
	var short = /^\d{4}$/;

	var strDay1 = '1';
	var strMonth1 = '1';
	var strYear1 = '';

	if (full.test(dtStr1)) {
		var dArr1 = dtStr1.split("/");
		strDay1 = dArr1[0];
		strMonth1 = dArr1[1];
		strYear1 = dArr1[2]; 
	} else if (medium.test(dtStr1)) {
		var dArr1 = dtStr1.split("/");    	
		strMonth1 = dArr1[0];
		strYear1 = dArr1[1];		
	} else if (short.test(dtStr1)) {
		strYear1 = dtStr1;
	}

	if (strDay1.charAt(0)=="0" && strDay1.length>1) strDay1=strDay1.substring(1);
	if (strMonth1.charAt(0)=="0" && strMonth1.length>1) strMonth1=strMonth1.substring(1);
	for (var i = 1; i <= 3; i++) {
		if (strYear1.charAt(0)=="0" && strYear1.length>1) strYear1=strYear1.substring(1);
	}

	var day1   = parseInt(strDay1, 10)
	var month1 = parseInt(strMonth1, 10)
	var year1  = parseInt(strYear1, 10)
	var myDate1 = new Date();
	myDate1.setFullYear(year1, month1 - 1, day1);
	if (dtStr2 == 'today') {
		var today = new Date();
		if (myDate1>today) {
			return "gtToday";
		} else if (myDate1<today) {
			return "ltToday";
		} else {
			return "eqToday"
		}
	}

	var strDay2 = '1';
	var strMonth2 = '1';
	var strYear2 = '';

	if (full.test(dtStr2)) {
		var dArr2 = dtStr2.split("/");
		strDay2 = dArr2[0];
		strMonth2 = dArr2[1];
		strYear2 = dArr2[2]; 
	} else if (medium.test(dtStr2)) {
		var dArr2 = dtStr2.split("/");    	
		strMonth2 = dArr2[0];
		strYear2 = dArr2[1];		
	} else if (short.test(dtStr2)) {
		strYear2 = dtStr2;
	}

	if (strDay2.charAt(0)=="0" && strDay2.length>1) strDay2=strDay2.substring(1);
	if (strMonth2.charAt(0)=="0" && strMonth2.length>1) strMonth2=strMonth2.substring(1);
	for (var i = 1; i <= 3; i++) {
		if (strYear2.charAt(0)=="0" && strYear2.length>1) strYear2=strYear2.substring(1);
	}

	var day2   = parseInt(strDay2, 10)	
	var month2 = parseInt(strMonth2, 10)	
	var year2  = parseInt(strYear2, 10)
	var myDate2 =new Date();
	myDate2.setFullYear(year2, month2 - 1, day2);

	if (myDate1>myDate2) {
		return "gt";
	} else if (myDate1<myDate2) {
		return "lt";
	} else {
		return "eq";
	}
}
/**
* get the checked attribute of html element such as: check box
* @param name: name of html element
* @return
* true : if element is check
* false : if element is not check
*/
function isChecked(name){
	var objArray	=	document.getElementsByName(name);
	var checked	=	false;
	for(var i=0; i < objArray.length; i++){
		if(objArray[i].checked){
			checked	=	true;
			break;
		}
	}
	return checked;
}

/**
* Check whether an hour is valid or not
* $param hour input hour string (Ex: "10:30")
* @return
* true : valid
* false : if not valid
*/

function checkHour(objHour, checkEmpty, message, target){
	var regxHour =  /^\d{1,2}:\d{2}$/;
	var hour = objHour.val();
	if (isNotEmpty(objHour, '', target) && regxHour.test(hour)){
		objHour.css("border-color", "#AAA");
		return true;
	} else if (!isNotEmpty(objHour, '', target) && !checkEmpty){
		objHour.css("border-color", "#AAA");
		return true;
	} else {
		objHour.css("border-color", "red");
		if (message == null || message == '') {
			message = _("Invalid time");
		}
		 $('span#' + target).css("font-style", "italic");
	    $('span#' + target).css("color","red");
		$('span#' + target).text(message).show();
		return false;
	}
	return true;
}

function validateNumberByLocal(objNum, lc, checkEmpty, message, target) {
	var val     =   objNum.val();
	 
	if (checkEmpty == false && $.trim(val) == '' ) {
		
		return true;
		
	}
	
	if (checkEmpty && !isNotEmpty(objNum, message, target)) {
	        return false;
	}
	
	var num     =   parseLcNum(val, lc);  
	    val =  val.replace(thousandSep, "");
	    val =  val.replace(decimalPoint, ".");
	    if (isNaN(val) || isNaN(num)) {
	        objNum.css("border-color", "red");
	        if (message == null || message == '') {
	            message = _("Invalid number");
	        }
	        $('span#' + target).text(message).show();        
	        return false;
	    }
	    objNum.css("border-color", "#AAA");
	    $('span#' + target).text('').show();
	    return true;
}

function validateIntegerByLocale(objNum, lc, checkEmpty, message, target) {
    if (checkEmpty && !isNotEmpty(objNum, message, target)) {
        return false;
    }
    var val     =   objNum.val();
    var num     =   parseLcNum(val, lc);
    val =  val.replace(thousandSep, "");
    if (isNaN(num) || (val != num)) {
        objNum.css("border-color", "red");
        if (message == null || message == '') {
            message = _("Invalid number");
        }
        $('span#' + target).text(message).show();        
        return false;
    }
    objNum.css("border-color", "#AAA");
    $('span#' + target).text('').show();
    return true;
}

function validatePositiveIntegerByLocale(objNum, lc, checkEmpty, message, target) {
    if (checkEmpty && !isNotEmpty(objNum, message, target)) {
        return false;
    }
    var val  =  objNum.val();
    var num  =  parseLcNum(val, lc);
    var pat  =  "[" + thousandSep + "]";
    var reg  =  new RegExp(pat, "g");
    val =  val.replace(reg, "");
    if (isNaN(num) || (val != num) || (num < 0)) {
        objNum.css("border-color", "red");
        if (message == null || message == '') {
            message = _("Invalid number");
        }
        $('span#' + target).text(message).show();        
        return false;
    }
    objNum.css("border-color", "#AAA");
    $('span#' + target).text('').show();
    return true;
}

function validatePositiveNumberByLocale(objNum, lc, checkEmpty, message, target) {
    if (checkEmpty && !isNotEmpty(objNum, message, target)) {
        return false;
    }
    var val     =   objNum.val();
    var num     =   parseLcNum(val, lc);
    val =  val.replace(thousandSep, "");
    val =  val.replace(decimalPoint, ".");
    if (isNaN(num) || (val != num) || (num < 0)) {
        objNum.css("border-color", "red");
        if (message == null || message == '') {
            message = _("Invalid number");
        }
        $('span#' + target).text(message).show();        
        return false;
    }
    objNum.css("border-color", "#AAA");
    $('span#' + target).text('').show();
    return true;
}

function allowNum(evt) {
	if (evt.which == 0 && (evt.keyCode == 37 || evt.keyCode == 38 || evt.keyCode == 39 || evt.keyCode == 40)) {
		return true;
	}
	if (evt.keyCode ==0 && evt.which >= 48 && evt.which <= 58) {
		return true;
	}
	if (evt.which == 8 || evt.keyCode == 8) {
		return true;
	}
	if (evt.which == 0 || evt.keyCode == 46) {
		return true;
	}
	if (evt.keyCode == 0 && (evt.which == 44 || evt.which == 45 || evt.which == 46)) {
		return true;
	}
	return false;
	
}

function allowEnterIntegerNum(evt, checkGeqZero)
{
	if (checkGeqZero == null) {
		checkGeqZero = false;
	}
	
	if (checkGeqZero == true && evt.which == 45) {
		return false;
	}
	
	if (!allowNum(evt)) {
		return false;
	}

	return true;
}

function checkIntMinMax(targetId, min, max, messageId, message)
{
	$('#' + targetId).css("border-color", "rgb(170, 170, 170)");
	if (targetId != '') {
		var lcInt = locale(decimalPoint, thousandSep, 0);
		var num = parseLcNum($('#' + targetId).val(), lcInt);
		if (!isNaN(num) && num >= min && num <= max) {
			return true;		
		} else {
			 $('#' + targetId).css("border-color", "red");
			 $('#' + messageId).css("font-style", "italic");
		     $('#' + messageId).css("color","red");		     
		     $('#' + messageId).html(message);
		     return false;
		}
		
	}
	return true;
}

function checkIntGt(targetId, min, messageId, message)
{
	$('#' + targetId).css("border-color", "rgb(170, 170, 170)");
	
	if (targetId != '') {
		var lcInt = locale(decimalPoint, thousandSep, 0);
		var num = parseLcNum($('#' + targetId).val(), lcInt);
		
		if (!isNaN(num) && num > min) {
			return true;		
		} else {
			 $('#' + targetId).css("border-color", "red");
			 $('#' + messageId).css("font-style", "italic");
		     $('#' + messageId).css("color","red");		     
		     $('#' + messageId).html(message);
		     return false;
		}
		
	}
	return true;
}

function isEraserKey(evt)
{
	
	if (evt.keyCode == 8 || evt.keyCode == 9 
			|| evt.keyCode == 13 || evt.keyCode == 32 
			|| evt.keyCode == 37 || evt.keyCode == 38
			|| evt.keyCode == 39 || evt.keyCode == 40
			|| evt.keyCode == 46) {
		return true;
	}	

	return false;
}

function allowEnterFloatNum(evt, checkGeqZero)
{
	if (checkGeqZero == null) {
		checkGeqZero = false;
	}
	
	if (checkGeqZero == true && evt.which == 45) {
		return false;
	}
	
	if (!allowNum(evt)) {
		return false;
	}

	return true;
}

function validateSelectBox(selectBoxId, message, targetId){
    if ( $('select#' + selectBoxId + ' option:selected').val() == 0 ) {
    	$('select#' + selectBoxId).css("border-color", "red");
        $('span#' + targetId).text(message).show();
        $('span#' + targetId).css("font-style", "italic");
        $('span#' + targetId).css("color","red");
        return false;
    }
    else {
    	$('select#' + selectBoxId).css("border-color", "#AAA");  
        return true;
    }
}

function checkBirthday(objYear, objMonth, objDay, objAge, mess, targetId) {
	if (mess == null) {
		mess = _('Empty date of birth');
	}
    var res     =   checkDate(objYear, objMonth, objDay, false, mess, targetId, true);
    if(!res){
        return false;
    }
    objAge.css("border-color", "#AAA");    
    return true;    
}
function checkAge(yId, mId, dId, aId, mess, targerId) {
	var yObj = $("input#" + yId);
	var mObj = $("input#" + mId);
	var dObj = $("input#" + dId);
	var aObj = $("input#" + aId);
	if (mess == null) {
		mess = _("Invalid age");
	}
	    if (aObj.val().length > 0 && !aObj.val().match(/^[0-9]+$/) || (aObj != null && aObj.val() <= 0)) {
	    	aObj.css("border-color", "red");
	    	aObj.focus();
	        $('span#' + targerId).text(mess).show();
	        return false;
	    } else if (aObj.val().length > 0) {
	    	aObj.css("border-color", "#AAA");
	    	yObj.css("border-color", "#AAA");
	    	mObj.css("border-color", "#AAA");
	    	dObj.css("border-color", "#AAA");
	        $('span#' + targerId).text('');
	        getBirthday(aId,yId);
	        return true;
	    } else {
	    	aObj.css("border-color", "#AAA");
	        $('span#' + targerId).hide();
	    }
	    return true;
	}